package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.ArticleDTO;
import com.ruoyi.system.domain.WaImage;
import com.ruoyi.system.domain.WaNotice;
import com.ruoyi.system.domain.vo.ArticleVo;
import com.ruoyi.system.mapper.WaImageMapper;
import com.ruoyi.system.service.WaImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.*;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;

@Service
public class WaImageServiceImpl  implements WaImageService {
    @Autowired
    private WaImageMapper imageMapper;
    //查询图片新闻列表
    @Override
    public List<WaImage> selectImageList(WaImage image) {
        return imageMapper.selectImageList(image);
    }
//通过类目类型获取文章
    @Override
    public List<WaImage> selectArticleByColumnById(WaImage image) {
        return imageMapper.selectArticleByColumnById(image);
    }
    //添加图片新闻
    @Override
    public int insertImage(WaImage image) {

        LocalDateTime currentTime = LocalDateTime.now();
        Date currentDate = Date.from(currentTime.atZone(ZoneId.systemDefault()).toInstant());
       image.setCreateTime(currentDate);
        image.setPublishTime(currentDate);
        return imageMapper.insertImage(image);
    }
//删除图片新闻
    @Override
    public int deleteImageById(Long imageId) {
        return imageMapper.deleteImageById(imageId);
    }

    @Override
    public boolean isArticleUsedImage(Long articleId) {
        if (articleId == null || articleId <= 0) {
            return false;
        }
        WaImage query = new WaImage();
        query.setArticleId(articleId);
        List<WaImage> imageList = imageMapper.selectImageList(query);
        return imageList != null && !imageList.isEmpty();
    }

    @Override
    public List<ArticleVo> selectArticle(ArticleDTO dto) {
        return imageMapper.selectArticle(dto);
    }

}
